var flag; //探针类型 标记；1 按探针编号； 2 按地区  3 自定义；
var flag2; //测试模型标记；

function showDialog() {
	$("#querypingTab").dialog("open");
	jQuery("#pGrid").jqGrid({
		url: IP + "GetProbeInfoList?callback=?&session=" + session,
		datatype: "jsonp",
		height: 230,
		width: 360,
		colNames: ['设备名称', '设备唯一编码'],
		colModel: [{
			name: 'deviceName',
			index: 'deviceName',
			sopt: ['eq'],
			width: 20
		}, {
			name: 'deviceid',
			index: 'deviceid',
			sopt: ['eq'],
			width: 40
		}],
		autowidth: false,
		shrinkToFit: true,
		//		shrinkToFit:false,
		loadonce: true,
		mtype: "GET",
		multiselect: true,
		multiselectWidth: 20,

		page: 1,
		colMenu: true,
		viewrecords: true
			//		sortorder: "asc",
			//		sortname: 'id'
	});
	var timer;
	$("#SearchCellPingId").on("keyup", function() {
		var self = this;
		if (timer) {
			clearTimeout(timer);
		}
		timer = setTimeout(function() {
			//timer = null;
			$("#pGrid").jqGrid('filterInput', self.value);
		}, 0);
	});

	$("#aGrid").jqGrid({
		url: IP + "GetAreaInfoList?callback=?&session=" + session,
		datatype: "jsonp",
		height: 230,
		width: 360,
		colModel: [{
			label: '序号',
			sorttype: 'integer',
			name: 'id',
			key: true,
			width: 65,
			hidden: true,
		}, {
			label: '地区',
			name: 'text',
			align: 'center',
			sopt: ['eq'],
			width: 125
		}],
		//		rowNum: -1,		
		loadonce: true,
		mtype: "GET",
		multiselect: true,
		multiselectWidth: 20,
		//rownumWidth: 40,
		//rowNum: 8,
		gridview: true,

		//page: 1,
		colMenu: true,
		viewrecords: true
			//sortorder: "asc",
			//sortname: 'id'
	});
	$("#SearchCellPingArea").on("keyup", function() {

		var self = this;
		if (timer) {
			clearTimeout(timer);
		}
		timer = setTimeout(function() {
			//timer = null;
			$("#aGrid").jqGrid('filterInput', self.value);
		}, 0);
	});

	$("#dGrid").jqGrid({
		url: IP + "GetProbeGroupInfo?callback=?&session=" + session,
		mtype: "Get",
		datatype: "jsonp",
		colModel: [{
			label: '序号',
			sorttype: 'integer',
			name: 'id',
			key: true,
			width: 30,
			hidden: true
		}, {
			label: '探针组',
			name: 'probeGroup',
			sopt: ['eq'],
			width: 40
		}, {
			label: '创建人',
			name: 'cPreson',
			sopt: ['eq'],
			width: 30
		}],
		loadonce: true,
		multiselect: true,
		multiselectWidth: 20,
		viewrecords: true,
		height: 230,
		width: 360,
		//rowNum: 8,
		page: 1,
		loadtext: '正在加载数据',
	});
	$("#SearchCellPingDefine").on("keyup", function() {
		var self = this;
		if (timer) {
			clearTimeout(timer);
		}
		timer = setTimeout(function() {
			//timer = null;
			$("#dGrid").jqGrid('filterInput', self.value);
		}, 0);
	});
}

//选取探针类型；
function searchProbe(current, at, state) {
	$("#probeDetail").empty();
	var arr = [];
	var Ids = $(current).jqGrid("getGridParam", "selarrrow");
	var len = Ids.length
	if (len == 0) {
		$.messager.show({
			title: '提醒',
			msg: '您什么也没选',
			timeout: 1300,
			showType: 'slide',
			style: {
				right: '',
				bottom: ''
			}
		});
		return false;
	} else {
		for (var i = 0; i < len; i++) {
			var getRow = $(current).getRowData(Ids[i]);
			arr.push(getRow[at]);
		}
		var str = arr.join(",");
		$("#probeDetail").val(str);
		$("#querypingTab").dialog("close");
		$(current).trigger("reloadGrid");
		flag = state;
	}

}

//探针类型切换
function changeType(isID, arr) {
	var $table = $("<table id='mGrid'><table><div id='mGridPager'></div>");
	$("#myBox").empty().html($table);
	var t = $("#testType").combobox("getValue");
	switch (t) {
		case "Ping":
			PingInit(isID, arr);
			break;
		case "TcpPing":
			getTcpingInit(isID, arr);
			break;
		case "NsLookUp":
			getDnsList(isID, arr);
			break;
		case "FtpDownload":
			getFtpDownLoad(isID, arr);
			break;
		case "FtpUpload":
			getFtpUpload(isID, arr);
			break;

		case "WebDownload":
			getWebDownload(isID, arr);
			break;
		case "HttpDownload":
			getHttpDownload(isID, arr);
			break;
		case "TraceRoute":
			getTracekRoute(isID, arr);
			break;
		case "RetrieveEmail":
			getRetrieveEMail(isID, arr);
			break;
		case "SendEmail":
			getSendEmail(isID, arr);
			break;
		default:
			$.messager.alert("提醒", "列表还没有生成，请耐心等待", "info")
	}

}
//加载ping列表

function PingInit(Id, arr) {
	$("#mGrid").jqGrid({
		url: IP + "GetProbeParam?callback=?&paramtype=Ping&session=" + session,
		mtype: "Get",
		datatype: "jsonp",
		colModel: [{
			label: '选择',
			name: 'ischeck',
			edittype: "checkbox",
			width: 50,
			editable: true,
			formatter: 'checkbox',
			align: "center",
		}, {
			label: '序号',
			//sorttype: 'integer',
			name: 'id',
			//key: true,
			align: "center",
			width: 50,
			hidden: true
		}, {
			label: '目标地址',
			name: 'destination',
			width: 150
		}, {
			label: '超时',
			name: 'timeout',
			width: 70
		}, {
			label: '包大小',
			name: 'packsize',
			width: 70
		}, {
			label: '间隔时间',
			name: 'pinginterval',
			width: 70
		}, {
			label: '循环次数',
			name: 'count',
			width: 70
		}, {
			label: '开始时间',
			name: 'startTime',
			formatter: 'HH:MM',
			width: 70
		}, {
			label: '结束时间',
			name: 'endTime',
			formatter: 'HH:MM',
			width: 70
		}],
		loadonce: true,
		viewrecords: true,
		onselectrow: true,
		autowidth: true,
		height: 160,
		rowNum: -1,
		//page: 1,
		scroll: true,

		loadComplete: function(data) {

			if (Id) {
				getTaskGroupParam(Id);
				Id = null;
			} else if (arr) {
				setTestParam(arr)

			} else {
				setEditRow();
			}
		},
		loadtext: '正在加载数据',

	})
}
//加载tcpping列表；

function getTcpingInit(Id, arr) {
	$("#mGrid").jqGrid({
		url: IP + "GetProbeParam?callback=?&session=" + session + "&paramtype=TcpPing",
		mtype: "Get",
		datatype: "jsonp",
		colModel: [{
			label: '选择',
			name: 'ischeck',
			edittype: "checkbox",
			width: 50,
			editable: true,
			align: "center",
			formatter: 'checkbox'
		}, {
			label: '序号',
			//sorttype: 'integer',
			name: 'id',
			//key: true,
			align: "center",
			width: 50,
			hidden: true,
		}, {
			label: '远程主机',
			name: 'destination',
			width: 90
		}, {
			label: '间隔时间',
			name: 'pinginterval',
			width: 70
		}, {
			label: '循环次数',
			name: 'count',
			width: 70
		}, {
			label: '端口',
			name: 'port',
			width: 70
		}, {
			label: 'TTL',
			name: 'ttl',
			width: 70
		}, {
			label: '超时',
			name: 'timeout',
			width: 60
		}, {
			label: '开始时间',
			name: 'startTime',
			formatter: 'HH:MM',
			width: 70
		}, {
			label: '结束时间',
			name: 'endTime',
			formatter: 'HH:MM',
			width: 70
		}],
		loadonce: true,
		viewrecords: true,
		onselectrow: true,
		autowidth: true,
		height: 160,
		rowNum: -1,
		//page: 1,
		scroll: true,

		loadComplete: function(data) {
			if (Id) {
				getTaskGroupParam(Id);
				Id = null;
			} else if (arr) {
				setTestParam(arr)

			} else {
				setEditRow();
			}
		},
		loadtext: '正在加载数据',

	})
}

function getFtpDownLoad(Id, arr) {
	$("#mGrid").jqGrid({
		url: IP + "GetProbeParam?callback=?&paramtype=FtpDownload&session=" + session,
		mtype: "Get",
		datatype: "jsonp",
		colModel: [{
			label: '选择',
			name: 'ischeck',
			edittype: "checkbox",
			width: 50,
			editable: true,
			align: "center",
			formatter: 'checkbox'
		}, {
			label: '序号',
			sorttype: 'integer',
			name: 'id',
			key: true,
			hidden: true,
			width: 50
		}, {
			label: '测试类型',
			name: 'testtype'
		}, {
			label: '单次测试超时(s)',
			name: 'timeout'
		}, {
			label: '目标地址',
			name: 'destination'
		}, {
			label: '端口',
			name: 'port'
		}, {
			label: '路径',
			name: 'path'
		}, {
			label: '存储标志',
			name: 'storefileflag'
		}, {
			label: '本地标志',
			name: 'localactiveflag'
		}, {
			label: '用户',
			name: 'user'
		}, {
			label: '指定每天开始时间',
			name: 'startTime'
		}, {
			label: '指定每天结束时间',
			name: 'endTime'
		}],
		loadonce: true,
		viewrecords: true,
		onselectrow: true,
		autowidth: true,
		height: 160,
		rowNum: -1,
		//page: 1,
		scroll: true,

		loadComplete: function(data) {
			if (Id) {
				getTaskGroupParam(Id);
				Id = null;
			} else if (arr) {
				setTestParam(arr)

			} else {
				setEditRow();
			}

		},
		loadtext: '正在加载数据',

	})
}

function getFtpUpload(Id, arr) {
	$("#mGrid").jqGrid({
		url: IP + "GetProbeParam?callback=?&paramtype=FtpUpload&session=" + session,
		mtype: "Get",
		datatype: "jsonp",
		colModel: [{
			label: '选择',
			name: 'ischeck',
			edittype: "checkbox",
			width: 50,
			editable: true,
			align: "center",
			formatter: 'checkbox'
		}, {
			label: '序号',
			sorttype: 'integer',
			name: 'id',
			key: true,
			hidden: true,
			width: 50
		}, {
			label: '测试类型',
			name: 'testtype'
		}, {
			label: '单次测试超时(s)',
			name: 'timeout'
		}, {
			label: '目标地址',
			name: 'destination'
		}, {
			label: '端口',
			name: 'port'
		}, {
			label: '路径',
			name: 'path'
		}, {
			label: '存储标志',
			name: 'storefileflag'
		}, {
			label: '本地标志',
			name: 'localactiveflag'
		}, {
			label: '用户',
			name: 'user'
		}, {
			label: '本地随机文件',
			name: 'uploadrandomlocalfile'
		}, {
			label: '指定每天开始时间',
			name: 'startTime'
		}, {
			label: '指定每天结束时间',
			name: 'endTime'
		}],
		loadonce: true,
		viewrecords: true,
		onselectrow: true,
		autowidth: true,
		height: 160,
		rowNum: -1,
		//page: 1,
		scroll: true,

		loadComplete: function(data) {
			if (Id) {
				getTaskGroupParam(Id);
				Id = null;
			} else if (arr) {
				setTestParam(arr)

			} else {
				setEditRow();
			}

		},
		loadtext: '正在加载数据',

	})
}

function getDnsList(Id, arr) {
	$("#mGrid").jqGrid({
		url: IP + "GetProbeParam?callback=?&paramtype=Nslookup&session=" + session,
		mtype: "Get",
		datatype: "jsonp",
		colModel: [{
			label: '选择',
			name: 'ischeck',
			edittype: "checkbox",
			width: 50,
			editable: true,
			align: "center",
			formatter: 'checkbox'
		}, {
			label: '序号',
			sorttype: 'integer',
			name: 'id',
			key: true,
			hidden: true,
			width: 70
		}, {
			label: '域名',
			name: 'domain',
			width: 150
		}, {
			label: '超时',
			name: 'timeout',
			width: 150
		}, {
			label: '开始时间',
			name: 'startTime',
			formatter: 'HH:MM',
			width: 150
		}, {
			label: '结束时间',
			name: 'endTime',
			formatter: 'HH:MM',
			width: 150
		}],
		loadonce: true,
		viewrecords: true,
		onselectrow: true,
		autowidth: true,
		height: 160,
		rowNum: -1,
		//page: 1,
		scroll: true,

		loadComplete: function(data) {
			if (Id) {
				getTaskGroupParam(Id);
				Id = null;
			} else if (arr) {
				setTestParam(arr)

			} else {
				setEditRow();
			}
		},
		loadtext: '正在加载数据',

	})
}

function getWebDownload(Id, arr) {
	$("#mGrid").jqGrid({
		url: IP + "GetProbeParam?callback=?&paramtype=WebDownload&session=" + session,
		mtype: "Get",
		datatype: "jsonp",
		colModel: [{
			label: '选择',
			name: 'ischeck',
			edittype: "checkbox",
			width: 50,
			editable: true,
			align: "center",
			formatter: 'checkbox',

		}, {
			label: '序号',
			sorttype: 'integer',
			name: 'id',
			key: true,
			hidden: true,
			width: 50
		}, {
			label: '测试类型',
			name: 'testtype',
			hidden: true,
		}, {
			label: '单次测试超时(s)',
			name: 'timeout'
		}, {
			label: '目标地址',
			name: 'destination'
		}, {
			label: '路径深度(s)',
			name: 'pathdepth'
		}, {
			label: '检索配额',
			name: 'retrievalquota'
		}, {
			label: '递归',
			name: 'recursive'
		}, {
			label: '指定每天开始时间',
			name: 'startTime'
		}, {
			label: '指定每天结束时间',
			name: 'endTime'
		}],
		loadonce: true,
		viewrecords: true,
		onselectrow: true,
		autowidth: true,
		height: 160,
		rowNum: -1,
		//page: 1,
		scroll: true,

		loadComplete: function(data) {
			if (Id) {
				getTaskGroupParam(Id);
				Id = null;
			} else if (arr) {
				setTestParam(arr)

			} else {
				setEditRow();
			}
		},
		loadtext: '正在加载数据',
	})
}

function getHttpDownload(Id, arr) {
	$("#mGrid").jqGrid({
		url: IP + "GetProbeParam?callback=?&paramtype=HttpDownload&session=" + session,
		mtype: "Get",
		datatype: "jsonp",
		colModel: [{
			label: '选择',
			name: 'ischeck',
			edittype: "checkbox",
			width: 50,
			editable: true,
			align: "center",
			formatter: 'checkbox',

		}, {
			label: '序号',
			sorttype: 'integer',
			name: 'id',
			key: true,
			hidden: true,
			width: 50
		}, {
			label: '测试类型',
			name: 'testtype',
			hidden: true,
		}, {
			label: '单次测试超时(s)',
			name: 'timeout'
		}, {
			label: '目标地址',
			name: 'destination'
		}, {
			label: '用户代理(s)',
			name: 'useragent'
		}, {
			label: '检索配额',
			name: 'retrievalquota'
		}, {
			label: '指定每天开始时间',
			name: 'startTime'
		}, {
			label: '指定每天结束时间',
			name: 'endTime'
		}],
		loadonce: true,
		viewrecords: true,
		onselectrow: true,
		autowidth: true,
		height: 160,
		rowNum: -1,
		//page: 1,
		scroll: true,

		loadComplete: function(data) {
			if (Id) {
				getTaskGroupParam(Id);
				Id = null;
			} else if (arr) {
				setTestParam(arr)

			} else {
				setEditRow();
			}
		},
		loadtext: '正在加载数据',
	})
}

function getTracekRoute(Id, arr) {
	$("#mGrid").jqGrid({
		url: IP + "GetProbeParam?callback=?&paramtype=TraceRoute&session=" + session,
		mtype: "Get",
		datatype: "jsonp",
		colModel: [{
			label: '选择',
			name: 'ischeck',
			edittype: "checkbox",
			width: 50,
			editable: true,
			align: "center",
			formatter: 'checkbox',

		}, {
			label: '序号',
			sorttype: 'integer',
			name: 'id',
			key: true,
			width: 50,
			hidden: true,
		}, {
			label: '测试类型',
			name: 'testtype',
			hidden: true,
		}, {
			label: '单次测试超时(s)',
			name: 'timeout'
		}, {
			label: '目标地址',
			name: 'destination'
		}, {
			label: '最大网段',
			name: 'maxttl'
		}, {
			label: '开始时间',
			name: 'startTime'
		}, {
			label: '结束时间',
			name: 'endTime'
		}],
		viewrecords: true,
		onselectrow: true,
		autowidth: true,
		height: 160,
		rowNum: -1,
		//page: 1,
		scroll: true,
		loadComplete: function(data) {
			if (Id) {
				getTaskGroupParam(Id);
				Id = null;
			} else if (arr) {
				setTestParam(arr)

			} else {
				setEditRow();
			}
		},
		loadtext: '正在加载数据',
	})
}

function getRetrieveEMail(Id, arr) {
	$("#mGrid").jqGrid({
		url: IP + "GetProbeParam?callback=?&paramtype=RetrieveEmail&session=" + session,
		mtype: "Get",
		datatype: "jsonp",
		colModel: [{
			label: '选择',
			name: 'ischeck',
			edittype: "checkbox",
			width: 50,
			editable: true,
			align: "center",
			formatter: 'checkbox',

		}, {
			label: '序号',
			sorttype: 'integer',
			name: 'id',
			key: true,
			width: 50,
			hidden: true
		}, {
			label: '测试类型',
			name: 'testtype',
			hidden: true
		}, {
			label: '单次测试超时(s)',
			name: 'timeout'
		}, {
			label: '目标地址',
			name: 'destination'
		}, {
			label: '用户',
			name: 'user'
		}, {
			label: '端口',
			name: 'port'
		}, {
			label: '支持SSL',
			name: 'supportssl'
		}, {
			label: '邮件类型',
			name: 'mailtype'
		}, {
			label: '开始时间',
			name: 'startTime'
		}, {
			label: '结束时间',
			name: 'endTime'
		}],
		viewrecords: true,
		onselectrow: true,
		autowidth: true,
		height: 160,
		rowNum: -1,
		//page: 1,
		scroll: true,

		loadComplete: function(data) {
			if (Id) {
				getTaskGroupParam(Id);
				Id = null;
			} else if (arr) {
				setTestParam(arr)

			} else {
				setEditRow();
			}
		},
		loadtext: '正在加载数据',
	})
}

function getSendEmail(Id, arr) {
	$("#mGrid").jqGrid({
		url: IP + "GetProbeParam?callback=?&paramtype=SendEmail&session=" + session,
		mtype: "Get",
		datatype: "jsonp",
		colModel: [{
			label: '选择',
			name: 'ischeck',
			edittype: "checkbox",
			width: 50,
			editable: true,
			align: "center",
			formatter: 'checkbox',

		}, {
			label: '序号',
			sorttype: 'integer',
			name: 'id',
			key: true,
			width: 50,
			hidden: true
		}, {
			label: '测试类型',
			name: 'testtype',
			hidden: true
		}, {
			label: '单次测试超时(s)',
			name: 'timeout'
		}, {
			label: '目标地址',
			name: 'destination'
		}, {
			label: '服务端口',
			name: 'serverPort'
		}, {
			label: '用户',
			name: 'user'
		}, {
			label: '端口',
			name: 'port'
		}, {
			label: '上传文件',
			name: 'uploadlocalfile'
		}, {
			label: '邮件类型',
			name: 'mailfrom'
		}, {
			label: '接收人',
			name: 'mailrecipients'
		}, {
			label: '主题',
			name: 'subject'
		}, {
			label: '内容',
			name: 'content'
		}, {
			label: '附件大小',
			name: 'attachmentsize'
		}, {
			label: '附件类型',
			name: 'attachmenttype'
		}, {
			label: '开始时间',
			name: 'startTime'
		}, {
			label: '结束时间',
			name: 'endTime'
		}],
		viewrecords: true,
		onselectrow: true,
		autowidth: true,
		height: 160,
		rowNum: -1,
		//page: 1,
		scroll: true,

		loadComplete: function(data) {
			if (Id) {
				getTaskGroupParam(Id);
				Id = null;
			} else if (arr) {
				setTestParam(arr)

			} else {
				setEditRow();
			}
		},
		loadtext: '正在加载数据',
	})
}
//参数组之间的切换；

function changeGroup(groupId, groupType) {
	$("#testType").combobox("disable");
	if (groupId == "init") {
		$("#testType").combobox("enable");
		$("#testType").combobox('setValue', initT);
		var $table = $("<table id='mGrid'><table><div id='mGridPager'></div>");
		$("#myBox").empty().html($table);
		PingInit(null);
	} else {
		var groupId = $("#paramGroup").combobox("getValue");
		$("#testType").combobox("setValue", groupType);
		changeType(groupId);
	}
}
//加载选中项；

function getTaskGroupParam(d) {
	$.ajax({
		url: IP + "GetParamIDS?&session=" + session + "&pid=" + d,
		type: "Get",
		dataType: "jsonp",
		jsonp: "callback",
		jsonpCallback: "resultHandler",
		success: function(json) {
			for (var i = 0; i < json.length; i++) {
				$("#mGrid").jqGrid('setCell', json[i].paramId, 0, 'Yes');
				//$("#testTypeList").jqGrid('editRow', json[i].paramId);
			}
			$("#mGrid").trigger("reloadGrid");
			setEditRow();
		}
	})
}

function changeModelType() {
	var moType = $("#modelType").combobox("getValue");
	if (moType == "init") {
		$("#paramGroup").combobox("enable");
		$("#testType").combobox("enable");
		$("#paramGroup").combobox("setValue", "init");
		$("#testType").combobox("setValue", initT);
		var $table = $("<table id='mGrid'><table><div id='mGridPager'></div>");
		$("#myBox").empty().html($table);
		PingInit(null);
	} else {
		$("#testType").combobox("disable");
		$("#paramGroup").combobox("disable");
	}
}

/*function addModel() {
		$("#modelDialog").dialog("open");
		var val = $("#testType").val();
		$("#" + val).siblings().css("display", "none");
		$("#" + val).css("display", "block");
	}
	//增加模板参数；

function saveParam(p) {
	console.log(p);
	switch (p) {
		case "Ping":
			savePing();
			break;
		case "TcpPing":
			saveTcpPing();
			break;

	}
}

function savePing() {
	if ($('#pingForm').form('enableValidation').form('validate')) {
		$.ajax({
			type: "post", // 与可以 "get"
			url: IP + "UpdatePingParam?callback=?&session=" + session,
			data: {
				id: 0,
				destination: $("#destination").val(),
				timeout: $("#timeout").val(),
				pinginterval: $("#pinginterval").val(),
				packsize: $("#packsize").val(),
				count: $("#count").val(),
				startTime: $("#startTime").val(),
				endTime: $("#endTime").val(),
			},
			dataType: "jsonp",
			jsonp: "callback",
			jsonpCallback: "resultHandler",
			success: function(json) {
				$("#modelDialog").dialog("close");
				if (json.result = 200) {
					$("#mGrid").addRowData(json.id, {
						id: json.id,
						destination: $("#destination").val(),
						timeout: $("#timeout").val(),
						pinginterval: $("#pinginterval").val(),
						packsize: $("#packsize").val(),
						count: $("#count").val(),
						startTime: $("#startTime").val(),
						endTime: $("#endTime").val(),
					}, '');
					insertopertlog('任务管理', 'Ping测试参数', '新增', '', $("#destination").val());
					$.messager.show({
						title: '提醒',
						msg: 'Ping参数增加成功',
						timeout: 1300,
						showType: 'slide',
						style: {
							right: '',
							bottom: ''
						}
					});
				} else {
					$.messager.alert('保存失败', json.message, 'error');
				}
				pingForm();
			}

		})
	}

}
function pingForm(){
	$('#pingForm').form('load', {
		//id: 0,
		destination: '',
		timeout: 60,
		packsize: 100,
		pinginterval: 10,
		count: 10,
		startTime: '00:00',
		endTime: '23:59',
	});
}*/

var paramArrayId; //测试参数Id；
var taskType; //参数类型；
var taskModelId; //模板id；
var taskModelName; //模板名字；
var probeInfo; //选取的探针；
var zlpgFlag;
var warningFlag;
var sDate;
var executeType; //执行方式；
var cycleIndex; //执行次数；
var timeInterval; //间隔时间；
function taskSend() {
	probeInfo = $("#probeDetail").val();
	if (!probeInfo) {
		$.messager.alert("提醒", "请选择探针", "info");
		return
	}

	executeType = $("input:radio[name='execute']:checked").val();
	cycleIndex = $("#cycleIndex").val();
	timeInterval = $("#timeInterval").val();
	sDate = $("#sDate").datetimebox('getValue');

	eDate = $("#eDate").datetimebox('getValue');

	if (executeType == 3) {
		eDate = "2999-12-30 00:00:00";

	}
	taskModelId = $("#modelType").combobox("getValue");
	//console.log(taskModelId);
	taskModelName = $("#modelType").combobox("getText");
	if (taskModelId == "init") {
		var paramId = '';
		var ids = $("#mGrid").jqGrid('getDataIDs');
		for (var i = 0; i < ids.length; i++) {
			if ($("#mGrid").getCell(ids[i], "ischeck") == 'Yes') {
				paramId += ids[i] + ",";
			}
		}
		if (paramId == '') {
			$.messager.alert("提醒", "你还没有选测试参数", 'info');
			return;
		}
		paramArrayId = paramId.substr(0, paramId.length - 1);
		flag2 = 1;
		taskType = $("#testType").combobox("getValue")
		taskModelId = 0;
		taskModelName = "无";
	} else {
		flag2 = 2;
		taskType = "自动选择";
		paramArrayId = "自动选择";
	}
	zlpgFalg = $("#zlpg").is(":checked") ? "1" : "0";
	warningFlag = $("#qyjg").is(":checked") ? "1" : "0";
	var cgl = $("#cGeneralLow").numberspinner("getValue");
	var cgh = $("#cGeneralHigh").numberspinner("getValue");
	var csl = $("#cSevereLow").numberspinner("getValue");
	var csh = $("#cSevereHigh").numberspinner("getValue");
	var ygl = $("#yGeneralLow").numberspinner("getValue");
	var ygh = $("#yGeneralHigh").numberspinner("getValue");
	var ysl = $("#ySevereLow").numberspinner("getValue");
	var ysh = $("#ySevereHigh").numberspinner("getValue");
	var wTimes = $("#wTimes").val();
	var id = $("#taskId").val();

	if ($('#exe').form('enableValidation').form('validate') && $('#warn').form('enableValidation').form('validate')) {
		$.ajax({
			url: IP + "UpdateTaskManage",
			Type: "POST",
			dataType: "jsonp",
			jsonp: "callback",
			jsonpCallback: "resultHandler",
			data: {
				session: session,
				id: id,
				probeInfo: probeInfo,
				flag: flag,
				flag2: flag2,
				executeType: executeType,
				sDate: sDate,
				eDate: eDate,
				cycleIndex: cycleIndex,
				timeInterval: timeInterval,
				taskType: taskType,
				taskModelId: taskModelId,
				taskModelName: taskModelName,
				zlpgFalg: zlpgFalg,
				warningFlag: warningFlag,
				wTimes: wTimes,
				cGeneralLow: cgl,
				cGeneralHigh: cgh,
				cSevereLow: csl,
				cSevereHigh: csh,
				yGeneralLow: ygl,
				yGeneralHigh: ygh,
				ySevereLow: ysl,
				ySevereHigh: ysh,
				paramArrayId: paramArrayId,
				taskState: "1"
			},
			success: function(json) {
				if (json.result == 200) {
					if ($("#taskId").val() == 0) {
						$("#jqGrid").addRowData(json.id, {
							id: json.id,
							probeInfo: probeInfo,
							flag: flag,
							flag2: flag2,
							executeType: executeType,
							sDate: sDate,
							eDate: eDate,
							cycleIndex: cycleIndex,
							timeInterval: timeInterval,
							taskType: taskType,
							taskModelId: taskModelId,
							taskModelName: taskModelName,
							zlpgFalg: zlpgFalg,
							warningFlag: warningFlag,
							wTimes: wTimes,
							cGeneralLow: cgl,
							cGeneralHigh: cgh,
							cSevereLow: csl,
							cSevereHigh: csh,
							yGeneralLow: ygl,
							yGeneralHigh: ygh,
							ySevereLow: ysl,
							ySevereHigh: ysh,
							paramArrayId: paramArrayId,
							taskState: "1"
						})
						insertopertlog('任务管理', '任务参数', '新增', '', $("#destination").val());
						$.messager.show({
							title: '提醒',
							msg: '任务下发成功',
							timeout: 1300,
							showType: 'slide',
							style: {
								right: '',
								bottom: ''
							}
						});
					} else {
						$("#jqGrid").setRowData($('#taskId').val(), {
							id: $('#taskId').val(),
							probeInfo: probeInfo,
							flag: flag,
							flag2: flag2,
							executeType: executeType,
							sDate: sDate,
							eDate: eDate,
							cycleIndex: cycleIndex,
							timeInterval: timeInterval,
							taskType: taskType,
							taskModelId: taskModelId,
							taskModelName: taskModelName,
							zlpgFalg: zlpgFalg,
							warningFlag: warningFlag,
							wTimes: wTimes,
							cGeneralLow: cgl,
							cGeneralHigh: cgh,
							cSevereLow: csl,
							cSevereHigh: csh,
							yGeneralLow: ygl,
							yGeneralHigh: ygh,
							ySevereLow: ysl,
							ySevereHigh: ysh,
							paramArrayId: paramArrayId,
						}, '');
						//insertopertlog('任务管理', '任务', '修改', oldvaluePing, $("#destination").val());
						$.messager.show({
							title: '提醒',
							msg: '任务修改成功',
							timeout: 1300,
							showType: 'slide',
							style: {
								right: '',
								bottom: ''
							}
						});
					}
				} else {
					$.messager.alert('保存失败', json.message, 'error');
				}
				mainInit();
			},
		})
	}

}
//设置行可编辑
function setEditRow() {
	var grid = $("#mGrid");
	var ids = grid.jqGrid('getDataIDs');
	for (var i = 0; i < ids.length; i++) {
		//grid.jqGrid('setCell',ids[i],0,true);
		grid.jqGrid('editRow', ids[i]);
	}
}
//保存行数据
function SaveEditedRows() {
	var grid = $("#mGrid");
	var ids = grid.jqGrid('getDataIDs');
	for (var i = 0; i < ids.length; i++) {
		grid.jqGrid('setCell', ids[i], 0, grid.getCell(ids[i], "ischeck"));
	}
}
//任务删除
function taskDelete() {
	var grid = $("#jqGrid");
	var rowKey = grid.jqGrid('getGridParam', "selrow");
	var oldvaluePing = $("#jqGrid").getCell(rowKey, "destination");
	if (rowKey) {
		$.messager.confirm('删除提醒', '你确认要删除任务---' + $("#jqGrid").getCell(rowKey, "taskType") + '?', function(r) {
			if (r) {
				$.ajax({
					type: "post", // 与可以 "get"
					url: IP + "DeleteProbeTask?callback=?",
					data: {
						id: rowKey,
						session: session,
						flag: 4,
					},
					dataType: "jsonp",
					jsonp: "callback",
					jsonpCallback: "resultHandler",
					success: function(json) {
						if (json.result == 200) {
							$("#jqGrid").delRowData(rowKey);
							insertopertlog('任务管理', '任务测试参数', '删除', oldvaluePing, '');
							$.messager.show({
								title: '提醒',
								msg: '删除成功',
								timeout: 1300,
								showType: 'slide',
								style: {
									right: '',
									bottom: ''
								}
							});
						} else {
							$.messager.alert('删除失败', json.message, 'error');
						}
					}
				});
				$("#taskSend").linkbutton("enable");
				$("#taskEdit").linkbutton("disable");
				$("#taskRetrun").linkbutton("disable");
				$("#taskSuspeed").linkbutton("disable");
				$("#taskDelete").linkbutton("disable");
			}
		});
	} else {
		$.messager.alert('提醒', "没有选中行", 'info');
	}
}
//任务挂起
function taskSuspeed() {
	var grid = $("#jqGrid");
	var rowKey = grid.jqGrid('getGridParam', "selrow");
	var oldvaluePing = $("#jqGrid").getCell(rowKey, "destination");
	var tState = $("#jqGrid").getCell(rowKey, "taskState");
	console.log(tState);
	if (rowKey) {
		$.messager.confirm('挂起提醒', '你确认要挂起任务---' + $("#jqGrid").getCell(rowKey, "taskType") + '?', function(r) {
			if (r) {
				if (tState == "2") {
					$.messager.alert('提醒', '任务已经挂起', 'info');
					return false;
				} else if (tState == "3") {
					$.messager.alert('提醒', '任务已经结束', 'info');
					return false;
				} else {
					$.ajax({
						type: "post", // 与可以 "get"
						url: IP + "DeleteProbeTask?callback=?",
						data: {
							id: rowKey,
							session: session,
							flag: 2,
						},
						dataType: "jsonp",
						jsonp: "callback",
						jsonpCallback: "resultHandler",
						success: function(json) {
							if (json.result == 200) {
								insertopertlog('任务管理', '任务测试参数', '挂起', oldvaluePing, '');

								$("#jqGrid").setRowData(rowKey, {
									taskState: "2",
								}, '');
								$.messager.show({
									title: '提醒',
									msg: '挂起成功',
									timeout: 1300,
									showType: 'slide',
									style: {
										right: '',
										bottom: ''
									}
								});
							} else {
								$.messager.alert('任务挂起失败', json.message, 'error');
							}
						}
					});
				}

			}
			$("#taskSend").linkbutton("enable");
			$("#taskEdit").linkbutton("disable");
			$("#taskRetrun").linkbutton("disable");
			$("#taskSuspeed").linkbutton("disable");
			$("#taskDelete").linkbutton("disable");

		});
	} else {
		$.messager.alert('提醒', "没有选任务", 'info');
	}

}
//任务恢复;
function taskReturn() {
	var grid = $("#jqGrid");
	var rowKey = grid.jqGrid('getGridParam', "selrow");
	var oldvaluePing = $("#jqGrid").getCell(rowKey, "destination");
	var tState = $("#jqGrid").getCell(rowKey, "taskState");
	if (rowKey) {
		$.messager.confirm('挂起提醒', '你确认要恢复任务---' + $("#jqGrid").getCell(rowKey, "taskType") + '?', function(r) {
			if (r) {
				if (tState == "1") {
					$.messager.alert('提醒', '任务正在執行', 'info');
					return false;
				} else if (tState == "3") {
					$.messager.alert('提醒', '任务已经结束', 'info');
					return false;
				} else {
					$.ajax({
						type: "post", // 与可以 "get"
						url: IP + "DeleteProbeTask?callback=?",
						data: {
							id: rowKey,
							session: session,
							flag: 1,
						},
						dataType: "jsonp",
						jsonp: "callback",
						jsonpCallback: "resultHandler",
						success: function(json) {
							if (json.result == 200) {
								insertopertlog('任务管理', '任务测试参数', '恢复', oldvaluePing, '');

								$("#jqGrid").setRowData(rowKey, {
									taskState: "1",
								}, '');
								$.messager.show({
									title: '提醒',
									msg: '任务恢复成功',
									timeout: 1300,
									showType: 'slide',
									style: {
										right: '',
										bottom: ''
									}
								});
							} else {
								$.messager.alert('任务恢复失败', json.message, 'error');
							}
						}
					});
				}
			}
			$("#taskSend").linkbutton("enable");
			$("#taskEdit").linkbutton("disable");
			$("#taskRetrun").linkbutton("disable");
			$("#taskSuspeed").linkbutton("disable");
			$("#taskDelete").linkbutton("disable");

		});
	} else {
		$.messager.alert('提醒', "没有选任务", 'info');
	}

}
//任务修改
/*function taskEdit() {
	$("#taskSend").linkbutton("enable");
	$("#taskDelete").linkbutton("disable");
	$("#taskEdit").linkbutton("disable");
	$("#taskSuspeed").linkbutton("disable");
	$("#taskRetrun").linkbutton("disable");

	var rowkey = $("#jqGrid").jqGrid("getGridParam", "selrow");
	if (rowkey) {
		var dataMain = $("#jqGrid").jqGrid('getRowData', rowkey);
		$("#taskId").val(dataMain["id"]);
		$("#probeDetail").val(dataMain["probeInfo"])
		var index = dataMain['executeType'] - 1;
		$("input[name=execute]:eq(" + index + ")").attr("checked", 'checked');
		$("#sDate").datetimebox("setValue", dataMain["sDate"]);
		$("#eDate").datetimebox("setValue", dataMain["eDate"]);
		$("#cycleIndex").numberspinner("setValue", dataMain["cycleIndex"]);
		$("#timeInterval").numberspinner("setValue", dataMain["timeInterval"]);
		if (dataMain["taskType"] == 0) {
			$("#testType").val("Ping");

		} else {
			$("#testType").val(dataMain["taskType"]);
		}

		$("#paramGroup").val("init");
		if (dataMain["taskModelId"] == 0) {
			$("#modelType").val("init");
		} else {
			$("#modelType").val(dataMain["taskModelName"]);
			$("#testType").attr("disabled", "true");
			$("#paramGroup").attr("disabled", "true");
		}

		if (dataMain["zlpgFalg"] == 1) {
			$("#zlpg").attr("checked", "true")
		} else {
			$("#zlpg").removeAttr("checked");
		}

		if (dataMain["warningFlag"] == 1) {
			$("#qyjg").attr("checked", "true")
		} else {
			$("#qyjg").removeAttr("checked");
		}

		$("#wTimes").numberbox("setValue", dataMain['wTimes']);

		$("#cGeneralLow").numberbox("setValue", dataMain["cGeneralLow"]);
		$("#cGeneralHigh").numberbox("setValue", dataMain["cGeneralHigh"]);
		$("#cSevereLow").numberbox("setValue", dataMain["cSevereLow"]);
		$("#cSevereHigh").numberbox("setValue", dataMain["cSevereHigh"]);

		$("#yGeneralLow").numberbox("setValue", dataMain["yGeneralLow"]);
		$("#yGeneralHigh").numberbox("setValue", dataMain["yGeneralHigh"]);
		$("#ySevereLow").numberbox("setValue", dataMain["ySevereLow"]);
		$("#ySevereHigh").numberbox("setValue", dataMain["ySevereHigh"]);

		var arr = dataMain["paramArrayId"].split(",");
		changeType(null, arr);
		//var paramArr = dataMain["paramArrayId"].split(",");
	} else {
		$.messager.alert("提醒", "你还没有选中行", "info")
	}
}*/

function setTestParam(arr) {
	for (var i = 0; i < arr.length; i++) {
		var k = arr[i];
		$("#mGrid").jqGrid('setCell', k, 0, 'Yes');
	}
	setEditRow();
}